<?php

namespace App\Http\Middleware;

use App\Models\MUser;
use Closure;

/**
 * 后台管理员权限页面检查
 */
class UserAuth
{
    public function handle($request, Closure $next)
    {
        if (!ss('uid')) {
            return redirect()->route('login.page');
        }//如果用户状态不是正常，不允许登录
        $user = MUser::find(ss('uid'));
        if ($user->status == MUser::$STATUS_STOP || $user->status == MUser::$STATUS_STOP_FREEZE) {
            $user->loginStatus($bool = false);
            return redirect()->route('login.page');
        }
        return $next($request);
    }
}
